public class MyCircularQueue {
    public int[] arr;
    public int front;
    public int rear;
    MyCircularQueue(int k) {
        this.arr = new int[k+1];
    }

    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        arr[rear] = value;
        rear = (rear+1)%arr.length;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        front = (front+1)%arr.length;
        return true;
    }

    public int Front() {
        if(isEmpty()){
            return -1;
        }
        return arr[front];
    }

    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        int index = -1;
        if(rear == 0){
            index = arr.length-1;
        }else{
            index = rear-1;
        }
        return arr[index];
    }

    public boolean isEmpty() {
        return rear == front;
    }

    public boolean isFull() {
        return (rear+1)%arr.length == front;
    }
}

